home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 147
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin
/
tools
/
zmc3v078
/
zmc3v078.lzh
/
SRCSV078.LZH
/
MAKEZMD2.C
< prev
next >
Wrap
Text File
|
2000-05-09
|
47KB
|
1,695 lines
/* ==================================
ZMS->ZMD playing track compile
================================== */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "switch.h"
#include "parsesub.h"
#include "makezmd.h"
#include "makezmd1.h"
#include "makezmd3.h"
#include "bracket.h"
#include "velo.h"
#include "etc.h"
#include "structs.h"
#include "structs2.h"
TRKCHINF *makeZmdMain(TRKCHINF *trkdata,UBYTE *zms, UBYTE **zms2,
COMMONINF *cominf, DWORD *totalstep);
UBYTE *makeZmdNote(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf,COMMONINF *cominf);
UBYTE *makeZmdNote1(UBYTE *zms, const int Trk,TRKINF *trkinf,BYTE *note);
UBYTE *getGate(UBYTE *zms, const int Trk,TRKINF *trkinf,UWORD step, UWORD *gate,int *err,
COMMONINF *cominf);
/* UWORD getGate1(const BYTE target[],TRKINF *trkinf,int trk,UWORD Step); */
UBYTE *makePortChord(UBYTE *zms, const int Trk,
TRKINF *trkinf,COMMONINF *cominf,
const UBYTE endchar,char allowcamma,
VELOETCVAR v[],BYTE note[],int *notes,
UWORD *step_, UWORD *gate_, UWORD *gate0,
WORD *delay, WORD *ptime);
UBYTE *makePlayTrack(UBYTE *zms,TRKINF *trkinf,TRKCHINF *trkdata,
COMMONINF *cominf,BYTE target[],int mode);
extern DWORD line,linebak;
extern char *linebuf;
extern LINEDATA *ld;
TRKCHINF *makeZmdMain(TRKCHINF *trkdata,UBYTE *zms, UBYTE **zms2,
COMMONINF *cominf, DWORD *totalstep)
{
int i, stat = 0, didPlayCommand = 0;
BYTE *target;
TRKINF *trkinf;
int trk, err;
DWORD tmpDWORD;
UBYTE *zms_;
UBYTE tmpUBYTE;
DWORD line_;
char *linebuf_;
LINEDATA *ld_;
target = (BYTE*)emalloc(sizeof(BYTE) * cominf->maxtrk,"target");
trkinf = (TRKINF*)emalloc(sizeof(TRKINF) * cominf->maxtrk,"trkinf");
for (i = 1; i < cominf->maxtrk; i++) {
/* for (i = 1; i < cominf->trkassign[i] >= 0; i++) {*/
initTrkInf(&trkinf[i], cominf);
trkinf[i].l = (LOOPDATA*)NULL;
trkinf[i].d = (LOOPDATA*)NULL;
trkinf[i].r = (RENP*)NULL;
trkinf[i].s = (CHKSTEP*)NULL;
trkinf[i].c = (CHKCHORD*)NULL;
initTrkInf2(&trkinf[i], i);
}
if (stricmp2(zms, ".track")) { /* not .track {.. */
if (*zms == '(') {
UBYTE *zms_ = zms;
zms = skipSpc(zms);
if (*zms != 't' && *zms != 'T') { /* not (T... */
target[0] = 1;
target[1] = -1;
cominf->trackmode = 0;
}
zms = zms_;
} else {
target[0] = 1;
target[1] = -1;
cominf->trackmode = 0;
}
}
while (1) {
zms = skipSpcCr(zms);
/* data = data_; */
zms_ = zms + 1; /* cant write this line inner switch{} */
linebuf_ = linebuf;
line_ = linebak = line;
ld_ = ld;
switch(*zms++) {
#ifdef A
case 0x1a: /* for MS-DOS */
#endif
case 0xFF: /* EOF */
for (trk = 0; cominf->trkassign[trk] >= 0; trk++) {
const int Trk = cominf->trkassign[trk];
*trkdata[Trk].zmd++ = 0xFF;
}
stat = -1;
break;
case '@':
/*OK*/ zms = makeZmdAtmark(zms,trkdata,target,trkinf,cominf);
break;
case '\"': /* @j old style || extended 8chord */
/*OK*/ zms = getnum2(zms, &tmpDWORD, &err);
if (err < 0) { /* no value -> extended chord*/
zms = makeZmdChord(zms,trkdata,target,trkinf,1,cominf);
zmserror("\"..\" can use only for zmc2.",line_,linebuf_,zms,4,1);
for (trk = 0; target[trk] >= 0; trk++) {
trkinf[target[trk]].noteon = 1;
}
} else { /* @j old style */
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0x9e;
*trkdata[Trk].zmd++ = (tmpDWORD)? 1 : 0;
}
}
break;
case '|': /* loop */
case ':':
/*OK*/ zms = makeZmdLoop1(--zms,trkdata,target,trkinf);
break;
case '[': /* [..] commands */
zms = makeZmdCommand(zms,trkdata,target,trkinf,cominf);
break;
case '\\': /* fadein/fadeout */
/*Ok*/ for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
line = line_;
ld = ld_;
zms = getnum2(zms_, &tmpDWORD, &err);
if (err < 0) {
tmpDWORD = 0; /* trkinf[target[trk]].fadeout; */
}
if (tmpDWORD < -128 || 127 < tmpDWORD) {
zmserror("fadein/out parameter is out of range(-128 - 127).",line_,linebuf_,zms_,3,1);
}
*trkdata[Trk].zmd++ = 0xD6;
putWord(trkdata[Trk].zmd, 0x7FFE);
trkdata[Trk].zmd += 2;
putWord(trkdata[Trk].zmd, 0); /* current track */
trkdata[Trk].zmd += 2;
*trkdata[Trk].zmd++ = 7;
if (tmpDWORD >= 0) {
putWord(trkdata[Trk].zmd, tmpDWORD * 0x100);
trkdata[Trk].zmd += 2;
*trkdata[Trk].zmd++ = 0x80;
*trkdata[Trk].zmd++ = 0;
} else {
putWord(trkdata[Trk].zmd, -tmpDWORD * 0x100);
trkdata[Trk].zmd += 2;
*trkdata[Trk].zmd++ = 0;
*trkdata[Trk].zmd++ = 0x80;
}
}
break;
case '=': /* switches */
/*OK*/ zms = getnum2(zms,&tmpDWORD,&err);
if (err < 0) {
tmpDWORD = 0;
}
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
const UBYTE cmd[4] = { 0x99, 0x98, 0xB3, 0x96 };
int i;
UBYTE match = 0x08;
for (i = 0; i < 4; i++) {
const UWORD data = (tmpDWORD & match)? 2 : 0;
*trkdata[Trk].zmd++ = cmd[i];
if (i == 2) {
putWord(trkdata[Trk].zmd, data);
trkdata[Trk].zmd += 2;
} else {
*trkdata[Trk].zmd++ = data;
}
match /= 2;
}
trkinf[Trk].veloseqsw = (tmpDWORD & 0x10)? 1 : 0;
}
break;
case '~': case '_': /* relative velocity up/down*/
/*tenuki */ tmpUBYTE = *(zms - 1); /* keep MML */
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
DWORD v = 0;
int err;
line = line_;
ld = ld_;
zms = zms_ - 1;
do {
DWORD vol;
zms = getnum2(zms + 1, &vol, &err);
if (err >= 0) {
trkinf[Trk].relvol = vol;
}
v += trkinf[Trk].relvol;
zms = skipSpc(zms);
} while (*zms == tmpUBYTE);
*trkdata[Trk].zmd++ = 0x91;
*trkdata[Trk].zmd++ = (tmpUBYTE == '~')? v : -v;
#ifdef AAA
/* (BEGIN FM/ADPCMsupport by Mamiya */
if (checkInternalDevice(trkdata,Trk) & 1) {
if (tmpUBYTE == '~')
v = trkinf[Trk].velou.var[0] + v ;
else
v = trkinf[Trk].velou.var[0] - v ;
v = (v < 0) ? 0 : ((v > 127) ? 127 : v) ;
trkinf[Trk].velou.var[0] = v ;
}
/* FM/ADPCMsupport by Mamiya END) */
#endif
}
break;
case '<': case '>': /* octave up/down */
/*OK*/ {
UBYTE *zms_ = --zms;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
zms = checkOctaveChange(zms_,trkinf,Trk);
}
}
break;
case '`': /* ` */
/*OK*/ makeZmdAllSoundOff(trkdata, target);
break;
case '{': /* renpu start */
zms = skipSpcCr(zms);
/*OK*/ if (*zms == '{') { /* */
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
char s[32];
sprintf(s,"trkinf[%d].s->next",Trk);
trkinf[Trk].s->next = (CHKSTEP*)emalloc(sizeof(CHKSTEP) * 1, s);
trkinf[Trk].s->next->prev = trkinf[Trk].s;
trkinf[Trk].s = trkinf[Trk].s->next;
trkinf[Trk].s->next = (CHKSTEP*)NULL;
trkinf[Trk].s->step = trkinf[Trk].total; /*0;*/
}
zms++;
zmserror("{{..}} can use only for zmc2.",line_,linebuf_,zms,4,1);
} else {
for (trk = 0; target[trk] >= 0; trk++) {
if (trkinf[target[trk]].renpnotes) {
zmserror("renpu{..} can't nest.",line,linebuf,zms,0,1);
}
trkinf[target[trk]].renpnotes = 1;
}
}
break;
case '}': /* renpu end */
/*OK*/ zms = skipSpcCr(zms);
if (*zms == '}') { /* }} */
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
UWORD step_;
UWORD usedstep = (UWORD)(trkinf[Trk].total - trkinf[Trk].s->step);
if (trkinf[Trk].s->prev == NULL) {
zmserror("no {{ found.",line,linebuf,zms,0,1);
}
line = line_;
ld = ld_;
zms = getStep(zms + 1, &step_, trkinf[Trk].Step,&err,cominf);
zms = skipSpcCr(zms);
zms = set98Tie(zms,&step_,trkinf[Trk].Step,cominf, &err);
if (step_ != usedstep) { /* (UWORD)trkinf[Trk].s->step) { */
char str[128];
sprintf(str,"{{..}}: %d ticks are reserved, but %d are in use.",
step_, usedstep);
zmserror(str,line_,linebuf_,zms_,2,1);
zmserror("{{..}} can use only for zmc2.",line_,linebuf_,zms_,4,1);
}
trkinf[Trk].s = trkinf[Trk].s->prev;
efree(trkinf[Trk].s->next,"trkinf[Trk].s->next");
trkinf[Trk].s->next = NULL;
#ifdef AAA
if (trkinf[Trk].s->prev) {
trkinf[Trk].s->step += step_;
}
#endif
}
} else {
zms = makeRenpuStepGate(zms,target,trkdata,trkinf,cominf);
}
break;
case 'a': case 'A': /* tone */
case 'b': case 'B':
case 'c': case 'C':
case 'd': case 'D':
case 'e': case 'E':
case 'f': case 'F':
case 'g': case 'G':
/*OK*/ /* [a-g](!+|[#+b-])*step,*gate,veloz[&] */
zms = makeZmdNote(zms,trkdata,target,trkinf,cominf);
for (trk = 0; target[trk] >= 0; trk++) {
trkinf[target[trk]].noteon = 1;
}
break;
case 'h': case 'H': /* wave-synchronous mode set */
/*
zms = makeZmdManyParas(zms,trkdata,target,line_,linebuf_,
0x9C, 0xFF, 2, 1, 1,
"i: too many parameters.",
"i: can't use relational parameters.",
"");
*/
/*OK*/ {
int err;
DWORD tmp;
zms = getnum2(zms,&tmp,&err);
if (err > 0) {
zmserror("H error.",line,linebuf,zms,0,1);
} else if (!err) {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0x97;
*trkdata[Trk].zmd++ = (tmp)? 0 : 0x80;
putWord(trkdata[Trk].zmd, 1);
trkdata[Trk].zmd += 2;
}
}
if (*zms == ',') {
zms = getnum2(++zms,&tmp,&err);
if (err > 0) {
zmserror("H error.",line,linebuf,zms,0,1);
} else if (!err) {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xB5;
*trkdata[Trk].zmd++ = 0x00;
*trkdata[Trk].zmd++ = (tmp)? 0 : 0x80;
putWord(trkdata[Trk].zmd, 1);
trkdata[Trk].zmd += 2;
}
}
}
}
break;
/*OK*/ case 'i': case 'I': /* bank select */
zms = makeZmdProgramBankChange(zms, trkdata, target);
break;
case 'k': case 'K': /* key transpose */
/*OK*/ zms = get1AbsPara(zms,&tmpDWORD,-128,127,
"key transpose parameter is out of range(-128 - 127).",
"`k'(key transpose) must be followed to its parameter.");
for (trk = 0; target[trk] >= 0; trk++) {
*trkdata[target[trk]].zmd++ = 0xAB;
*trkdata[target[trk]].zmd++ = trkinf[target[trk]].transpose = tmpDWORD;
}
break;
case 'l': case 'L': /* set default step */
/*OK*/ for (trk = 0; target[trk] >= 0; trk++) {
UWORD step;
int err;
line = line_;
ld = ld_;
zms = getStep(zms_, &step, trkinf[target[trk]].Step, &err,cominf);
trkinf[target[trk]].Step = step;
}
break;
case 'm': case 'M': /* MIDI pitch modulation mode set */
/*
zms = makeZmdManyParas(zms,trkdata,target,line_,linebuf_,
0x99, 0xFF, 2, 1, 1,
"m: too many parameters.",
"m: can't use relational parameters.",
"");
*/
/*OK*/
{
int err;
DWORD tmp;
zms = getnum2(zms,&tmp,&err);
if (err > 0) {
zmserror("M error.",line,linebuf,zms,0,1);
} else if (!err) {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0x95;
*trkdata[Trk].zmd++ = tmp - 1;
}
}
if (*zms == ',') {
zms = getnum2(++zms,&tmp,&err);
if (err > 0) {
zmserror("M error.",line,linebuf,zms,0,1);
} else if (!err) {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xB4;
*trkdata[Trk].zmd++ = 0x00;
*trkdata[Trk].zmd++ = tmp - 1; /* (tmp)? 1 : -1; */
}
}
}
}
break;
case 'n': case 'N': /* channel change */
/*tenuki*/ zms = get1AbsPara(zms,&tmpDWORD,1,32,
"channel change parameter is out of range(1 - 32).",
"`n'(channel change) must be followed to its parameter.");
for (trk = 0; target[trk] >= 0; trk++) {
BYTE ch = 0;
const int Trk = target[trk];
if (cominf->basech) { /* (B1) MIDI mode */
if (tmpDWORD <= 16) {
ch = tmpDWORD + 8;
} else if (tmpDWORD <= 8 + 1 + 16) {
ch = tmpDWORD - 17;
/* (BEGIN debug??? by Mamiya */
} else {
ch = tmpDWORD - 1;
/* debug??? by Mamiya END) */
}
} else {
ch = tmpDWORD - 1;
}
*trkdata[Trk].zmd++ = 0xCC;
putWord(trkdata[Trk].zmd, 0x8000);
putWord(trkdata[Trk].zmd + 2, ch - 9);
trkdata[Trk].zmd += 4;
/*
fprintf(stderr,"%d:%x %x %x %x %x %x %x\n",
Trk,
*(trkdata[Trk].zmd-6),
*(trkdata[Trk].zmd-5),
*(trkdata[Trk].zmd-4),
*(trkdata[Trk].zmd-3),
*(trkdata[Trk].zmd-2),
*(trkdata[Trk].zmd-1),
*(trkdata[Trk].zmd));
*/
}
break;
case 'o': case 'O': /* octave set */
/*OK*/ {
UBYTE *zms_ = --zms;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
zms = checkOctaveChange(zms_,trkinf,Trk);
}
}
break;
case 'p': case 'P': /* panpot set */
zms = makeZmdPanpot(zms, trkdata, target, -1);
#ifdef A
{
/*tenuki*/ const int tbl[] = {128, 0, 127, 64};
zms = get1AbsPara(zms,&tmpDWORD,0,3,
"panpot parameter is out of range(0-3).",
"`p'(panpot set) must be followed to its parameter.");
for (trk = 0; target[trk] >= 0; trk++) {
*trkdata[target[trk]].zmd++ = 0xA0;
*trkdata[target[trk]].zmd++ = tbl[tmpDWORD];
}
}
#endif
break;
case 'q': case 'Q': /* quantization */
zms = makeZmdQuantize(zms,cominf->qmode,target,trkinf);
break;
case 's': case 'S': /* modulation wave pattern select */
/*
zms = makeZmdManyParas(zms,trkdata,target,line_,linebuf_,
0x98, 0xFF, 2, 1, 1,
"s: too many parameters.",
"s: can't use relational parameters.",
"");
*/
/*OK*/ {
int err;
DWORD tmp;
zms = getnum2(zms,&tmp,&err);
if (err > 0) {
zmserror("S error.",line,linebuf,zms,0,1);
} else if (!err) {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xB0;
if (tmp >= 8) {
tmp += 0x8000 - 8;
}
putWord(trkdata[Trk].zmd, tmp);
trkdata[Trk].zmd += 2;
}
}
if (*zms == ',') {
zms = getnum2(++zms,&tmp,&err);
if (err > 0) {
zmserror("H error.",line,linebuf,zms,0,1);
} else if (!err) {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xC9;
*trkdata[Trk].zmd++ = 0x00;
if (tmp >= 8) {
tmp += 0x8000 - 8;
}
putWord(trkdata[Trk].zmd, tmp);
trkdata[Trk].zmd += 2;
}
}
}
}
break;
case 't': case 'T': /* tempo */
zms = makeZmdTempo(zms,trkdata,target,0);
break;
/*OK*/ case 'u': case 'U': /* velocity */
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
BYTE rel = 0;
DWORD velo;
int err;
line = line_;
ld = ld_;
zms = skipSpcCr(zms_);
if (*zms == '+') {
rel = 1;
} else if (*zms == '-') {
rel = -1;
}
zms = getnum2(zms, &velo, &err);
zms = skipSpcCr(zms);
if (*zms == ':' && *(zms + 1) != '|') {
DWORD r = trkinf[Trk].velou.var[1];
/* DWORD rp = (r)? rand2(r) : 0; */
int err2;
zms = skipSpcCr(zms + 1);
zms = getnum2(zms, &r, &err2);
r = abs(r);
/* rp = (r && !err2)? rand2(r) : 0; */
trkinf[Trk].velou.var[1] = r;
}
if (rel) {
*trkdata[Trk].zmd++ = 0x94;
*trkdata[Trk].zmd++ = velo; /* + rp; */
#ifdef AA
} else if (rel < 0) {
*trkdata[Trk].zmd++ = 0xCB;
*trkdata[Trk].zmd++ = -velo; /* + rp; */
#endif
} else {
int v = trkinf[Trk].veloofst;
if (err < 0) { /* only 'u' */
v += trkinf[Trk].velou.var[0]; /* + rp; */
} else {
trkinf[Trk].velou.var[0] = velo;
v += velo;
/* *trkdata[Trk].zmd++ = velo; */ /* + rp */;
}
if (v > 127) {
v = 127;
} else if (v < 0) {
v = 0;
}
*trkdata[Trk].zmd++ = 0x93;
*trkdata[Trk].zmd++ = v;
}
/* trkinf[Trk].veloznum = 0; */
setVelocitySequenceMode(trkinf,Trk,0);
}
break;
case 'v': case 'V': /* volume */
zms = makeZmdVolume(zms, trkdata, target, trkinf, -1);
#ifdef A
/* MIDI OK */
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
DWORD vol; /* ,v = trkinf[Trk].vol; */
int err;
line = line_;
ld = ld_;
zms = getnum2(zms_, &vol, &err);
if (err < 0) { /* only 'v' */
zmserror("`v'(volume change) must be followed to its parameter.",line,linebuf,zms,0,1);
} else {
if (vol < 0 || vol > 16) {
zmserror("volume parameter is out of range.",line,linebuf,zms,0,1);
/* (BEGIN FM/ADPCMsupport by Mamiya */
} else if (checkInternalDevice(trkdata,Trk) & 1) {
/*
const BYTE vtblFM[17] = {
85,87,90,93,95,98,101,103,106,109,111,114,117,119,122,125,127
};
*/
*trkdata[Trk].zmd++ = 0x90;
/* *trkdata[Trk].zmd++ = 127 - vtblFM[vol];
trkinf[Trk].velou.var[0] = vtblFM[vol] ; */
*trkdata[Trk].zmd++ = 0x80 + vol;
trkinf[Trk].velou.var[0] = vol;
/* FM/ADPCMsupport by Mamiya END) */
} else {
*trkdata[Trk].zmd++ = 0x90;
*trkdata[Trk].zmd++ = 0x80 + vol;
/* trkinf[Trk].vol = vtbl[vol]; */
}
trkinf[Trk].volmode = 1;
}
}
#endif
break;
case 'w': case 'W': /* send/receive track synchoronous*/
zms = makeZmdSynchronize(zms, trkdata, target, cominf);
break;
case 'x': case 'X': /* Roland exclusive */
zms = makeZmdExclusive(zms, trkdata, target, 0x41);
break;
case 'y': case 'Y': /* control change */
zms = makeZmdCChange(zms,trkdata,target);
break;
case 'z': case 'Z': /* velocity sequence */
zms = makeZmdVeloSeq(zms,trkdata,target,trkinf);
break;
case 'r': case 'R':
/*OK*/ for (trk = 0; target[trk] >= 0; trk++) {
UWORD step,gate;
int err,omitgate;
const int Trk = target[trk];
line = line_;
ld = ld_;
zms = getStep(zms_, &step, trkinf[Trk].Step,&err,cominf);
zms = getGate(zms,Trk,trkinf,step,&gate,&omitgate,cominf);
zms = skipSpcCr(zms);
if (*zms == ',') { /* dummy velocity */
zms = getnum2(zms + 1,&tmpDWORD,&err);
}
zms = setTie(zms, trkdata, Trk, trkinf,
0x80, &step, &gate, 0, omitgate,
trkinf[Trk].Step,cominf,0);
incrementStepCounters(&trkinf[Trk],step);
#ifdef AAa
if (!trkinf[Trk].renpnotes) {
trkinf[Trk].total += step;
if (trkinf[Trk].s->prev) {
trkinf[Trk].s->step += step;
}
}
#endif
if (gate != 0xFFFF) {
freeAllChord(trkinf[Trk].c);
}
}
break;
case '\'': /* chord */
/*OK*/ zms = makeZmdChord(zms,trkdata,target,trkinf,0,cominf);
for (trk = 0; target[trk] >= 0; trk++) {
trkinf[target[trk]].noteon = 1;
}
break;
case '.':
if (!stricmp2(zms, "track")) {
zms += 5;
zms = makePlayTrack(zms,trkinf,trkdata,cominf,target,0);
#ifdef A
if (cominf->trackmode) {
zmserror("'}' is not closed.",line,linebuf,zms,0,1);
} else {
cominf->trackmode = 1;
}
{
int c = 0;
DWORD trk;
int err;
while (*zms != '{') {
int i = 0 - 1,chkflag = 0;
char errstr[80];
zms = getnum2(zms,&trk,&err);
if (err && c == 0 && *zms == '{' ) { /* (t) */
zmserror("no track number is assigned.",line,linebuf,zms,0,1);
}
while (cominf->trkassign[++i] >= 0) {
if (cominf->trkassign[i] == trk) {
chkflag = 1;
break;
}
}
if (!chkflag) {
sprintf(errstr,"trk %d is not assigned.",trk);
zmserror(errstr,line,linebuf,zms,0,1);
}
while (trkdata[trk].backinuse >= 0) {
trk = trkdata[trk].backinuse;
}
target[c++] = trk;
target[c] = -1;
zms = skipSpc(zms);
if (!strchr(",{", *zms)) {
/* char str[128]; */
/* sprintf(str,"%.2x illegal partion character.",*zms); */
zmserror("illegal partition character.",line,linebuf,zms,0,1);
}
if (*zms == ',') {
zms++;
} else if (*zms == 0xFF && *(zms + 1) == 0xFF) { /* EOF */
zmserror("unexpected EOF.",line,linebuf,zms,0,1);
}
}
zms++;
}
#endif
break;
} else {
UBYTE *zms2;
/*fprintf(stderr,"[.2s]");*/
zms--;
makeZmdCommon(trkdata,zms,&zms2,cominf,1);
/*fprintf(stderr,"[.2e]");*/
zms = zms2;
/* zmserror("UNknown MML",line,linebuf,zms,0,1); */
break;
}
case '(':
zms = skipSpc(zms);
switch(*zms++) {
case 'a': case 'A': case 'b': case 'B': /* portament */
case 'c': case 'C': case 'd': case 'D':
case 'e': case 'E': case 'f': case 'F':
case 'g': case 'G': case 'o': case 'O':
case '<': case '>':
zms = makePortament(zms - 1,trkdata,target,trkinf,cominf,')');
for (trk = 0; target[trk] >= 0; trk++) {
trkinf[target[trk]].noteon = 1;
}
break;
case 'p': case 'P': /* (P...) */
#ifdef AA
zms = skiptochr(zms,")"); /* ignore */
zms++;
break;
#endif
if (cominf->trackmode) {
zmserror("'}' is not closed.",line,linebuf,zms,0,1);
}
{
int c = 0;
DWORD trk;
int err;
didPlayCommand = 1;
do {
int i = 0 - 1,chkflag = 0, playalltrk = 0;
char errstr[80];
zms = getnum2(zms,&trk,&err);
if (!c++) {
int i;
/* loop's 1st time */
if ( err && *zms == ')') {
playalltrk = 1; /* (p) */
} else {
for (i = 0; cominf->trkassign[i] >= 0; i++) {
const int t = cominf->trkassign[i];
trkdata[t].mute = 0;
}
}
}
while (cominf->trkassign[++i] >= 0) {
int Trk = cominf->trkassign[i];
if (playalltrk || cominf->trkassign[i] == trk) {
chkflag = 1;
do {
trkdata[Trk].mute = 1;
Trk = trkdata[Trk].backinuse;
} while (Trk >= 0);
break;
}
}
if (!chkflag) {
sprintf(errstr,"trk %d is not assigned.",trk);
zmserror(errstr,line,linebuf,zms,0,1);
}
zms = skipSpc(zms);
if (!strchr(",)", *zms)) {
/* char str[128]; */
/* sprintf(str,"%.2x illegal partion character.",*zms); */
zmserror("illegal partition character.",line,linebuf,zms,0,1);
}
if (*zms == ',') {
zms++;
} else if (*zms == 0xFF && *(zms + 1) == 0xFF) { /* EOF */
zmserror("unexpected EOF.",line,linebuf,zms,0,1);
}
} while (*zms != ')');
if (cominf->backinuse) { /* there is [back..] trk */
int i;
setSwitchVal('z',3); /* disable the trk deleting */
for (i = 0; cominf->trkassign[i] >= 0; i++) {
int Trk = cominf->trkassign[i];
if (!trkdata[Trk].mute) {
*trkdata[Trk].zmdbuf = 0xFF;
trkdata[Trk].zmd = trkdata[Trk].zmdbuf + 1;
} /* kill the tracks */
}
}
zms++;
}
break;
case 't': /* (T...) */
case 'T':
zms = makePlayTrack(zms,trkinf,trkdata,cominf,target,1);
#ifdef A
if (cominf->trackmode) {
zmserror("'}' is not closed.",line,linebuf,zms,0,1);
} else {
cominf->trackmode = 0;
}
{
int c = 0;
DWORD trk;
int err;
while (*zms != ')') {
int i = 0 - 1,chkflag = 0;
char errstr[80];
zms = getnum2(zms,&trk,&err);
if (err && c == 0 && *zms == ')' ) { /* (t) */
zmserror("no track number is assigned.",line,linebuf,zms,0,1);
}
while (cominf->trkassign[++i] >= 0) {
if (cominf->trkassign[i] == trk) {
chkflag = 1;
break;
}
}
if (!chkflag) {
sprintf(errstr,"trk %d is not assigned.",trk);
zmserror(errstr,line,linebuf,zms,0,1);
}
while (trkdata[trk].backinuse >= 0) {
trk = trkdata[trk].backinuse;
}
target[c++] = trk;
target[c] = -1;
zms = skipSpc(zms);
if (!strchr(",)", *zms)) {
/* char str[128]; */
/* sprintf(str,"%.2x illegal partion character.",*zms); */
/* fprintf(stderr,"[%c]\n",*zms); */
zmserror("illegal partition character.",line,linebuf,zms,0,1);
}
if (*zms == ',') {
zms++;
} else if (*zms == 0xFF && *(zms + 1) == 0xFF) { /* EOF */
zmserror("unexpected EOF.",line,linebuf,zms,0,1);
}
}
zms++;
/*
printf("Target:");
for (trk = 0; target[trk] >= 0; trk++) {
printf("%d,",target[trk]);
}
printf("\n");
*/
}
#endif
break;
default:
{
UBYTE *zms2;
zms--;
makeZmdCommon(trkdata,zms,&zms2,cominf,1);
zms = zms2;
}
/*zmserror("Unknown MML",line,linebuf,zms,0,1);*/
break;
}
break;
case '/':
zms = skipComment(zms);
break;
case ']': /* end of [back...] */
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
const int fromtrk = cominf->fromtrk[Trk];
trkdata[Trk].backinuse = -1;
if (fromtrk < 0) {
zmserror("']' nest error.",line, linebuf,zms,0,1);
} else {
target[trk] = fromtrk;
}
}
break;
/* (BEGIN FM/ADPCMsupport by Mamiya */
case 'j': case 'J': /* replay */
/*tenuki*/ zms = makeZmdReplay(zms, trkdata, target);
break;
#ifdef A
case 'j': case 'J':
zms = getnum2(zms_, &tmpDWORD, &err);
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
if (err < 0) {
zmserror("restart(`j') must be followed to its parameter.",line_,linebuf_,zms_,0,1);
} else if (tmpDWORD < 1 || MAXTRK <= tmpDWORD) {
zmserror("track number is out of range.",line_,linebuf_,zms_,0,1);
} else {
int i, f = 0;
for (i = 0; i < cominf->maxtrk; i++) {
if (cominf->trkassign[i] == tmpDWORD) {
*trkdata[Trk].zmd++ = 0xCE;
*trkdata[Trk].zmd++ = i; /* - 1; */
f = 1;
break;
}
}
if (!f) {
zmserror("illegal track number.",line_,linebuf_,zms_,0,1);
} else {
zmserror("restart(`j') will be ignored by many drivers.",line_,linebuf_,zms_ - 1,3,1);
}
}
}
#endif
case '?':
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
BYTE rel = 0;
DWORD address;
line = line_;
ld = ld_;
zms = getnum2(zms_,&address,&err);
if (err < 0) {
zmserror("workarea control(`?') must be followed to its parameter.",line_,linebuf_,zms_,0,1);
} else if (address < 0 || 255 < address) {
zmserror("work address is out of range.",line_,linebuf_,zms_,0,1);
}
zms = skipSpcCr(zms);
if (*zms != ',') {
zmserror("workarea control(`?') must have 2 parameters.",line_,linebuf_,zms_,0,1);
} else {
zms = skipSpcCr(zms + 1);
}
if (*zms == '+' || *zms == '-') rel = 1;
zms = getnum2(zms,&tmpDWORD,&err);
if (err < 0) {
zmserror("workarea control(`?') must have 2 parameters.",line_,linebuf_,zms_,0,1);
} else {
if (!rel) {
*trkdata[Trk].zmd++ = 0xD5;
*trkdata[Trk].zmd++ = address;
*trkdata[Trk].zmd++ = tmpDWORD;
} else if (tmpDWORD < 0) {
*trkdata[Trk].zmd++ = 0xD8;
*trkdata[Trk].zmd++ = address;
*trkdata[Trk].zmd++ = -tmpDWORD;
} else {
*trkdata[Trk].zmd++ = 0xD7;
*trkdata[Trk].zmd++ = address;
*trkdata[Trk].zmd++ = tmpDWORD;
}
zmserror("workarea control(`?') will be ignored by many drivers.",line_,linebuf_,zms_ - 1,3,1);
}
}
break;
case ';':
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
line = line_;
ld = ld_;
zms = zms_ - 1;
do {
zms = getnum2(zms + 1,&tmpDWORD,&err);
if (err < 0) break;
*trkdata[Trk].zmd++ = tmpDWORD;
zms = skipSpcCr(zms);
} while(*zms == ',');
zmserror("It's too dangerous to insert ZMD data directly.",line_,linebuf_,zms_ - 1,3,1);
}
break;
/* FM/ADPCMsupport by Mamiya END) */
default:
{
UBYTE *zms2;
zms--;
makeZmdCommon(trkdata,zms,&zms2,cominf,1);
zms = zms2;
}
#ifdef A
if (*zms != ' ' && *zms != '\t' && *zms != 0x0d && *zms != 0x0a && *zms != 0x1a && *zms != 0xff) {
/* fprintf(stderr,"err! %.2X %c\n",*zms,*zms); */
zmserror("unknown MML.",line,linebuf,zms,2,1);
}
zms++;
#endif
break;
}
if (stat) {
break;
} else {
for (trk = 0; target[trk] >= 0; trk++) { /* memory leak check */
const int Trk = target[trk];
const DWORD bs = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
if (bs > trkdata[Trk].bufsize - MTRK_OVERFLOW_RANGE) {
char s[32];
sprintf(s,"trkdata[%d].zmdbuf",Trk);
trkdata[Trk].bufsize += FIRST_MTRK_SIZE;
trkdata[Trk].zmdbuf = (UBYTE*)erealloc(trkdata[Trk].zmdbuf,sizeof(UBYTE) * trkdata[Trk].bufsize,s);
trkdata[Trk].zmd = trkdata[Trk].zmdbuf + bs;
}
}
}
}
*zms2 = zms;
*totalstep = 0;
if (!didPlayCommand) { /* without (p) command */
if (cominf->backinuse) { /* there is [back..] trk */
setSwitchVal('z',3); /* disable the trk deleting */
}
}
{
int i,j;
/*
fprintf(stderr,"[%d]",cominf->trkassign[0]);
fprintf(stderr,"[%d]",cominf->trkassign[1]);
*/
/*
for (i = 1; i < cominf->maxtrk; i++) {
*/
/*memdebug();*/
for (i = 0, j = 0; cominf->trkassign[i] >= 0; i++, j++) {
const int Trk = cominf->trkassign[i];
/*
const int Trk = i;
*/
char errmes[80];
/*fprintf(stderr,"[%d]",cominf->trkassign[i]);*/
trkdata[Trk].nowsize = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
/*fprintf(stderr,"TrkSize=%d ",trkdata[Trk].nowsize);*/
if (*totalstep < trkinf[Trk].total) {
*totalstep = trkinf[Trk].total;
}
/*fprintf(stderr,"Trk%d: total %d\n",Trk,trkinf[Trk].total);*/
if (trkdata[Trk].nowsize & 3) { /* padding if need */
const int len = trkdata[Trk].nowsize & 3;
int j;
for (j = len; j < 4; j++) {
*trkdata[Trk].zmd++ = 0xFF;
trkdata[Trk].nowsize++;
}
}
freeAllChord(trkinf[Trk].c);
/* #ifdef A */
if (trkinf[Trk].renpnotes) {
sprintf(errmes,"`}' is not closed in track %d.",Trk);
zmserror(errmes,line,linebuf,zms,0,0);
resetError();
}
if (trkinf[Trk].l->prev) {
if (trkinf[Trk].l->loopmode >= 0) {
sprintf(errmes,":| is not closed in track %d.",Trk);
zmserror(errmes,line,linebuf,zms,3,0);
resetError();
}
do {
trkinf[Trk].l = trkinf[Trk].l->prev;
efree(trkinf[Trk].l->next,"trkinf[Trk].l->next");
} while (trkinf[Trk].l->prev);
}
if (trkinf[Trk].d->looptime) {
sprintf(errmes,"[do]~[loop] is not closed in track %d.",Trk);
zmserror(errmes,line,linebuf,zms,3,0);
resetError();
/*
do {
trkinf[Trk].d = trkinf[Trk].d->prev;
efree(trkinf[Trk].d->next);
} while (trkinf[Trk].d->prev);
*/
}
if (trkinf[Trk].s->prev) {
sprintf(errmes,"`}}' is not closed in track %d.",Trk);
zmserror(errmes,line,linebuf,zms,4,0);
resetError();
do {
trkinf[Trk].s = trkinf[Trk].s->prev;
efree(trkinf[Trk].s->next,"trkinf[Trk].s->next");
} while (trkinf[Trk].s->prev);
}
/* #endif */
/*fprintf(stderr,"[freeTrkInf %d]\n",Trk);*/
freeTrkInf(&trkinf[Trk],Trk);
}
/*fprintf(stderr,"((%d))\n",j);*/
for (i = 1; i < cominf->maxtrk; i++) { /* no BACK trk supported */
/*fprintf(stderr,"[freeTrkInf %d]\n",i);*/
freeTrkInf(&trkinf[i],i);
}
}
efree(trkinf,"trkinf");
efree(target,"target");
return trkdata;
}
UBYTE *makeZmdNote(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf,COMMONINF *cominf)
{
int trk;
char *zms_ = zms - 1;
/* UBYTE *data_ = data; */
DWORD line_ = line;
LINEDATA *ld_ = ld;
VELOETCVAR v;
int warnoct = 0;
WORD velo;
/* v = (VELOETCVAR*)emalloc(sizeof(VELOETCVAR) * 1); */
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
BYTE note,relvelo = 0;
UWORD step,gate,looptime = trkinf[Trk].echolp;
/* DWORD velo; */
int err,omitgate = 0;
BYTE *qpos = &(trkinf[Trk].quantizepos);
const int beforeOctave = trkinf[Trk].octave;
UBYTE *linebuf_;
v.var[0] = 0;
v.relflg[0] = 2;
/* data = data_; */
line = line_;
ld = ld_;
/* note */
zms = makeZmdNote1(zms_,Trk,trkinf,¬e);
/* printf("(%.2x)",note); */
zms = checkOctaveChange(zms,trkinf,Trk);
/* step */
zms = getStep(zms, &step, trkinf[Trk].Step,&err,cominf);
zms = checkOctaveChange(zms,trkinf,Trk);
/* gate */
zms = getGate(zms,Trk,trkinf,step,&gate,&omitgate,cominf);
zms = checkOctaveChange(zms,trkinf,Trk);
/* velo */
zms = getSpecialVelocity(zms,&v);
velo = setVelo0(trkdata,Trk,v,&relvelo,trkinf,cominf,step);
linebuf_ = linebuf;
zms = skipSpcCr(zms);
zms = set98Tie(zms, &step, trkinf[Trk].Step, cominf, &err);
if (omitgate == 2) {
gate = getGate1(Trk,trkinf,step);
}
zms = skipSpcCr(zms);
if (*zms == '&') { /* tie */
gate = 0x8000;
zms++;
}
if (looptime != 1) {
if (relvelo == 0) {
relvelo = 1;
velo = trkinf[Trk].echodec;
}
while ( (looptime > 1) || (looptime == 0) && (step > trkinf[Trk].echoitv) ) {
/* break when: (looptime == 1) || (looptime == 0 && step <= echoitv) */
/*
relvelo == 1: relative velo
relvelo == 0: detault velo
relvelo = -1: special velo
*/
zms = setTie2(zms,trkdata,Trk,trkinf,
note,trkinf[Trk].echoitv, trkinf[Trk].echoitv,
relvelo,0,velo);
step -= trkinf[Trk].echoitv;
if (gate > trkinf[Trk].echoitv) {
gate -= trkinf[Trk].echoitv;
} else {
gate = 0;
}
velo += trkinf[Trk].echodec;
if (looptime) {
looptime--;
}
#ifdef A
zms = setTie(zms, trkdata, Trk, trkinf, /* TIE */
note, &step, gate, relvelo, omitgate,
trkinf[Trk].Step,cominf,velo);
#endif
}
}
zms = setTie(zms, trkdata, Trk, trkinf, /* last 1 time */
note, &step, &gate, relvelo, omitgate,
trkinf[Trk].Step,cominf,velo);
/* if (trkinf[Trk].quantize[++*qpos].relflg[0] < 0) { */
if (++*qpos >= trkinf[Trk].quantizenum) {
*qpos = 0;
}
if (gate == 0x8000 && beforeOctave != trkinf[Trk].octave && !warnoct && step != 1) {
zmserror("There is octave switch(es) between NOTE and TIE.",line_,linebuf_,zms_,3,2);
warnoct = 1;
}
incrementStepCounters(&trkinf[Trk], step);
if (trkinf[Trk].veloseqsw) { /* add v0.74 */
vSeqLoopChk(Trk,trkinf);
}
#ifdef AAA
if (!trkinf[Trk].renpnotes) {
trkinf[Trk].total += step;
if (trkinf[Trk].s->prev) {
trkinf[Trk].s->step += step;
}
}
#endif
if (gate != 0xFFFF) {
freeAllChord(trkinf[Trk].c);
} else {
DWORD gatepos = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
addNextChkChord(trkinf[Trk].c, note, gatepos, gate);
}
/* fprintf(stderr,"(t=%d)",trkinf[Trk].total); */
}
return zms;
}
/* ==================
get tone (sub)
================== */
UBYTE *makeZmdNote1(UBYTE *zms, const int Trk,TRKINF *trkinf,BYTE *note)
{
/* const int Trk = target[trk]; */
const BYTE tonetbl[7] = { 0, 2, 4, 5, 7, 9, 11 };
const char *dstr_ = "#+--!";
BYTE d[3] = { 0, 0, 0 }; /* number of #+,b-,! */
char *dstr;
*note = (*zms++ | 0x20) - 'a';
*note -= 2; /* c→0 a→-2 */
if (*note < 0) {
*note += 7;
}
*note = tonetbl[*note]; /* without #/b */
zms = skipSpcCr(zms);
while ( (dstr = strchr(dstr_,*zms)) != NULL) {
d[((const char *)dstr - dstr_) / 2]++;
if (d[2]) {
if (d[2] > 1) {
zmserror("too many natural(!).",line,linebuf,zms,0,1);
} else if (d[0] || d[1]) {
zmserror("natural(!) must be on just after note.",line,linebuf,zms,0,1);
}
}
zms = skipSpcCr(++zms);
}
if (!d[2]) {
*note += trkinf[Trk].ksign[*note % 12]; /* with KSIGN */
}
*note += d[0];
*note -= d[1]; /* #/b is reflected */
#ifdef A /* you should omit transpose in V3 */
*note += trkinf[Trk].transpose; /* transpose is reflected */
#endif
*note += (trkinf[Trk].octave + 1) * 12;
/* #/b,transpose,octrave are reflected */
return zms;
}
/* ======================
get gate parameter
====================== */
UBYTE *getGate(UBYTE *zms, const int Trk,TRKINF *trkinf,UWORD step, UWORD *gate,int *err,
COMMONINF *cominf)
{
/* const int Trk = target[trk]; */
if (*zms == ',') {
zms = getStep(++zms, gate, trkinf[Trk].Step, err, cominf);
if (*err == 2) { /* if gate is omitted */
*gate = getGate1(Trk,trkinf,step);
}
} else {
*err = 2;
*gate = getGate1(Trk,trkinf,step);
}
/*
if ((step < *gate) && step) {
zmserror("step < gate.",line,linebuf,zms,3,1);
}
*/
return zms;
}
/* ==
portament/chord
*/
UBYTE *makePortChord(UBYTE *zms, const int Trk,
TRKINF *trkinf,COMMONINF *cominf,
const UBYTE endchar,char allowcamma,
VELOETCVAR v[],BYTE note[],int *notes,
UWORD *step_, UWORD *gate_, UWORD *gate0,
WORD *delay, WORD *ptime)
{
char *zms_ = zms - 1;
char *linebuf_ = linebuf;
DWORD line_ = line;
LINEDATA *ld_ = ld;
/*
UBYTE *zms_ = zms;
*/
/* const int Trk = target[trk]; */
UWORD step;
int i,err,steps = 0;
int beforeOctave = trkinf[Trk].octave;
DWORD tmpDWORD;
const UWORD Step = trkinf[Trk].Step;
const BYTE portflg = (endchar == ')' || endchar == ']')? 1 : 0;
*notes = 0;
*step_ = trkinf[Trk].Step;
*gate_ = getGate1(Trk,trkinf,*step_);
/* *gate0 = *gate_; */ /* add v0.74 */
/* *delay = trkinf[Trk].pdelay; */
/* fprintf(stderr,"[s=%d/g=%d/d=%d]",*step_,*gate_, *delay); */
for (i = 0; (i < 8 + 1 && !(*notes)); ) {
UBYTE *tmpzms;
zms = skipSpc(zms);
switch(*zms) {
case 'a': case 'A': case 'b': case 'B':
case 'c': case 'C': case 'd': case 'D':
case 'e': case 'E': case 'f': case 'F':
case 'g': case 'G':
err = 0;
zms = makeZmdNote1(zms,Trk,trkinf,¬e[i]);
zms = getStep(zms, &step,Step,&err,cominf);
if (err != 2) {
*gate_ = getGate1(Trk,trkinf,step);
}
/*if (!portflg) { */
{
UWORD newgate1, newgate2;
int omitgate;
int omitgate2;
int err98;
v[i].var[0] = 0;
v[i].relflg[0] = 2;
zms = getGate(zms,Trk,trkinf,step,&newgate1,&omitgate,cominf);
zms = getSpecialVelocity(zms,&v[i]);
/* fprintf(stderr,"{%d:%d/%d}",i,v[i].var[0],v[i].relflg[0]); */
/*
if (omitgate != 2) {
*gate_ = newgate1;
}
*/
tmpzms = zms = skipSpc(zms);
zms = set98Tie(zms,&step,Step,cominf, &err98);
/*UWORD gate;*/
/*UWORD newgate;*/
/*v[i].var[0] = 0;*/
/* v[i].relflg[0] = 2; */
zms = getGate(zms,Trk,trkinf,step,&newgate2,&omitgate2,cominf);
zms = getSpecialVelocity(zms,&v[i]);
/* fprintf(stderr,"{{%d:%d/%d}}",i,v[i].var[0],v[i].relflg[0]); */
if (err != 2 || err98 != 2) { /* step & gate will be change */
/* err == 0: there is parameter */
/* == 1: only dot(.) there */
/* == 2: omit all parameters */
if (++steps > 1 && *step_ != step) {
zmserror("too many steps in a chord/portament.",line_,linebuf_,zms_,0,1);
} else {
*step_ = step;
if (omitgate2 == 2 && omitgate == 2) {
*gate_ = getGate1(Trk,trkinf,*step_);
} else {
if (omitgate != 2) {
*gate_ = newgate1;
} else {
*gate_ = newgate2;
}
}
}
/*fprintf(stderr,"[og1=%d og2=%d er=%d er2=%d]",omitgate, omitgate2, err,err98);*/
}
}
i++;
break;
case 'o':
case '<': case '>':
zms = checkOctaveChange(zms,trkinf,Trk);
break;
case ',':
#ifdef A
if (allowcamma) {
zms++;
} else {
zmserror("SYNTAX ERROR.",line_,linebuf_,zms_,0,1);
}
#endif
zms++;
break;
case '\'':
case '\"':
case ')':
case ']':
if (*zms == endchar) {
*notes = i;
zms++;
} else {
zmserror("SYNTAX ERROR.",line_,linebuf_,zms_,0,1);
}
break;
default:
zmserror("SYNTAX ERROR.",line_,linebuf_,zms_,0,1);
break;
}
}
if (!portflg) {
trkinf[Trk].octave = beforeOctave;
} else {
beforeOctave = trkinf[Trk].octave;
}
zms = getnum2(zms,&tmpDWORD,&err); /* gate */
if (err >= 0) { /* there is a (ticked)step parameter */
*step_ = tmpDWORD;
*gate_ = getGate1(Trk,trkinf,*step_);
} else if (*zms == '*') {
zms = getnum2(++zms,&tmpDWORD,&err);
if (err >= 0) { /* there is a (ticked)step parameter */
*step_ = tmpDWORD;
*gate_ = getGate1(Trk,trkinf,*step_);
}
}
zms = checkOctaveChange(zms,trkinf,Trk);
if (*zms == ',') { /* delay */
zms = skipSpcCr(zms + 1);
/*#ifdef A */
if (*zms == '*') {
zms++;
}
/*#endif */
zms = getnum2(zms,&tmpDWORD,&err);
if (err) {
zmserror("no delay parameter is specified.",line_,linebuf_,zms_,0,1);
}
*delay = tmpDWORD;
}
zms = checkOctaveChange(zms,trkinf,Trk);
if (*zms == ',') { /* portament time */
if (portflg) {
zmserror("Portament time can't set on the chord.",line_,linebuf_,zms_,0,1);
}
zms = skipSpcCr(zms + 1);
#ifdef A
if (*zms == '*') {
zms++;
}
#endif
zms = getnum2(zms,&tmpDWORD,&err);
if (err) {
zmserror("no portament time is specified.",line_,linebuf_,zms_,0,1);
}
*ptime = tmpDWORD;
}
zms = checkOctaveChange(zms,trkinf,Trk);
zms = skipSpcCr(zms);
zms = set98Tie(zms,step_,Step,cominf,&err);
/* *gate_ = getGate1(Trk,trkinf,*step_); */
zms = skipSpcCr(zms);
*gate0 = *gate_; /* add v0.74 */
/* fprintf(stderr,"[s=%d/g=%d/d=%d]",*step_,*gate_, *delay); */
if (*zms == '&') { /* tie */
*gate_ = (portflg)? 0x8000 : 0xFFFF;
if (beforeOctave != trkinf[Trk].octave) {
zmserror("There is octave switch(es) between NOTE and TIE.",line_,linebuf_,zms_,3,1);
}
zms++;
}
/*fprintf(stderr,"[s=%d/g=%d/d=%d]",*step_,*gate_, *delay);*/
if (*delay > *gate_) {
/*fprintf(stderr,"[g=%d/d=%d]",*gate_, *delay);*/
zmserror("delay must be less than the gate.",line_,linebuf_,zms_,0,1);
}
#ifdef A
if (*step_ == 1 && cominf->l1tie) { /* gate is *1 */
*gate_ = 0xFFFF;
}
#endif
return zms;
}
UBYTE *makePlayTrack(UBYTE *zms,TRKINF *trkinf,TRKCHINF *trkdata,
COMMONINF *cominf,BYTE target[],int mode)
/* mode=0: .track 1:(t) */
{
int c = 0, err;
DWORD trk;
const char endchar[2] = { '{' , ')' };
const char *endchar2[2] = { ",{", ",)" };
if (cominf->trackmode) {
zmserror("'}' is not closed.",line,linebuf,zms,0,1);
} else {
cominf->trackmode = 1 - mode;
}
while (*zms != endchar[mode]) {
int i = 0 - 1,chkflag = 0;
char errstr[80];
zms = getnum2(zms,&trk,&err);
if (err && c == 0 && *zms == endchar[mode] ) { /* (t) */
zmserror("no track number is assigned.",line,linebuf,zms,0,1);
}
/*
fprintf(stderr,"Request:%d\n",trk);
while (cominf->trkassign[++i] >= 0) {
fprintf(stderr,"[%d_%d]",i,cominf->trkassign[i]);
}
i = 0 - 1;
*/
while (cominf->trkassign[++i] >= 0) {
if (cominf->trkassign[i] == trk) {
chkflag = 1;
break;
}
}
/*fprintf(stderr,"cf=%d",chkflag);*/
if (!chkflag) {
if (0 < trk && trk < 16) { /* omit (AMIDIn,n) */
BYTE trks;
for (trks = 0; cominf->trkassign[trks] >= 0; trks++) {
}
makeZmdAssignMain(trkdata, cominf, trk, &trks, trk - 1, 0x8000);
/* initTrkInf0(trkdata, cominf->trkassign[trks - 1]); */
sprintf(errstr,"track %d is not assigned; (AMIDI%d,%d) is made up.",trk,trk,trk);
zmserror(errstr,line,linebuf,zms,3,1);
} else if (trk <= 0) {
zmserror("illegal track number is specified.",line,linebuf,zms,0,1);
} else {
sprintf(errstr,"track %d is not assigned.",trk);
zmserror(errstr,line,linebuf,zms,0,1);
}
}
while (trkdata[trk].backinuse >= 0) {
trk = trkdata[trk].backinuse;
}
target[c++] = trk;
target[c] = -1;
zms = skipSpc(zms);
if (!strchr( endchar2[mode], *zms)) {
/* char str[128]; */
/* sprintf(str,"%.2x illegal partion character.",*zms); */
/* fprintf(stderr,"[%c]\n",*zms); */
zmserror("illegal partition character.",line,linebuf,zms,0,1);
}
if (*zms == ',') {
zms++;
} else if (*zms == 0xFF && *(zms + 1) == 0xFF) { /* EOF */
zmserror("unexpected EOF.",line,linebuf,zms,0,1);
}
}
zms++;
/*
printf("Target:");
for (trk = 0; target[trk] >= 0; trk++) {
printf("%d,",target[trk]);
}
printf("\n");
*/
return zms;
}